function e(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

function t(e, t, r) {
    var i = [];
    return e && e.split(",").forEach(function(e) {
        i.push(d[parseInt(e, 10)]);
    }), e ? "所选服务时间超出商家营业时间(周" + i.join("、 ") + ", " + a(t) + "-" + a(r) + "), 请重新选择" : "该站点暂未设置上班时间,无法提交预约！";
}

function a(e) {
    var t = Math.floor(e / 3600), a = Math.floor(e / 60) % 60;
    return ("" + t).padStart(2, "0") + ":" + ("" + a).padStart(2, "0");
}

function r(e) {
    var t = e.app, a = e.applyid, r = e.mchid, i = e.total_fee, n = getApp().globalData, o = {
        openid: n.tokens.openid,
        appid: n.appid,
        from: "site_service",
        fee: i,
        applyid: "" + a
    };
    return new Promise(function(e, a) {
        u.default.v4["site" === t ? "swiftpass" : "wechatpay"].prepay({
            data: o,
            query: {
                app: "site" === t ? "site" : +r
            }
        }).then(function(t) {
            var r = t.jsparams;
            wx.requestPayment(s({}, r, {
                success: e,
                fail: a
            }));
        }).catch(a);
    });
}

function i(e) {
    return u.default.site.site.view({
        data: {
            sid: e
        }
    }).then(function(e) {
        return e.mchid;
    });
}

function n(e) {
    wx.showModal({
        title: "操作提示",
        content: e,
        showCancel: !1,
        confirmText: "我知道了",
        success: function(e) {
            e.confirm && wx.redirectTo({
                url: "/pages/profile/reservationlist/reservationlist"
            });
        }
    });
}

function o() {
    for (var e = new Date(), t = [], a = 0; a < 7; a++) {
        var r = new Date(e.getFullYear(), e.getMonth(), e.getDate() + a);
        t.push(r.getFullYear() + "-" + ("" + (r.getMonth() + 1)).padStart(2, "0") + "-" + ("" + r.getDate()).padStart(2, "0"));
    }
    return t;
}

function p(e, t) {
    for (var a = parseInt(e.split(":")[0], 10), r = parseInt(t.split(":")[0], 10), i = [], n = a; n <= r; n++) i.push(("" + n).padStart(2, "0"));
    return i;
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var s = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
        var a = arguments[t];
        for (var r in a) Object.prototype.hasOwnProperty.call(a, r) && (e[r] = a[r]);
    }
    return e;
}, u = e(require("./api2")), c = e(require("./util")), l = e(require("./config")), d = [ "一", "二", "三", "四", "五", "六", "日" ];

exports.default = {
    MODEL_PROJECT: "services_project",
    MODEL_USER: "services_staff",
    _isWorkingTimeRange: function(e) {
        var a = e.time, r = e.workday, i = e.worktimebegin, n = e.worktimeend;
        if (new Date().getTime() > new Date(a.replace(/-/g, "/")).getTime()) return {
            isTimeValid: !1,
            vailTimeTip: "所选服务时间早于当前时间，请重新选择"
        };
        var o = a.split(" "), p = new Date(o[0].replace(/-/g, "/")).getDay() - 1, s = r.split(",").includes("" + (-1 === p ? 6 : p)), u = o[1].split(":"), c = 3600 * parseInt(u[0], 10) + 60 * parseInt(u[1], 10), l = c >= i && c <= n;
        return {
            isTimeValid: s && l,
            vailTimeTip: t(r, i, n)
        };
    },
    _formateInitTime: function(e, t) {
        var r = [];
        return e = a(e), t = a(t), r.push(o()), r.push(p(e, t)), r.push([ "00", "30" ]), 
        r;
    },
    getUserCardContent: function(e) {
        return new Promise(function(t, a) {
            u.default.v4.weappcard.view({
                data: e
            }).then(function(e) {
                t(e.card);
            });
        });
    },
    submitReservation: function(e, t, a) {
        var i = t.app, o = t.mchid;
        u.default.site.servicesorder.addv2({
            data: e,
            desc: "提交预约"
        }).then(function(e) {
            return 0 != +e.total_fee && e.ispay ? "wxwork" === getApp().globalData.environment ? (n("企业微信内暂不支持支付！请前往微信--小程序，搜索：“小官网”后进入对应官网进行支付。"), 
            void (a && a())) : void r(s({
                app: i,
                mchid: o
            }, e)).then(function(e) {
                n("您的服务预约已提交成功！"), a && a();
            }).catch(function() {
                n("支付失败，你可以稍后在我的预约页面继续完成支付");
            }) : (n("您的服务预约已提交成功！"), void (a && a()));
        });
    },
    servicePay: r,
    payServiceOrder: function(e) {
        if (!e.appid) return Promise.reject("订单不支持支付");
        var t = function(e) {
            return c.default.qAlert(e, "支付提示", "我知道了");
        }, a = e.appid === l.default.SITE_APPID, n = e.appname, o = getApp().globalData, p = o.app, s = o.sid;
        return a && "thirdparty" === p ? t("该订单是在“小官网”小程序创建的，请前往“小官网”--“我的预约”支付") : a || "site" !== p ? "wxwork" === getApp().globalData.environment ? (wx.showModal({
            title: "提示",
            content: "企业微信内暂不支持支付！请前往微信--小程序，搜索：“小官网”后进入对应官网进行支付。",
            showCancel: !1,
            confirmText: "我知道了"
        }), Promise.reject()) : "thirdparty" === p ? i(s).then(function(t) {
            return r({
                app: p,
                mchid: t,
                applyid: e.applyid,
                total_fee: e.total_fee
            });
        }) : r({
            app: "site",
            mchid: 0,
            applyid: e.applyid,
            total_fee: e.total_fee
        }) : t("该订单是在“" + (n || "独立") + "小程序”创建的，请前往“" + (n || "独立") + "小程序”--“我的预约”支付");
    },
    openSiteLocation: function(e) {
        var t = e.addresslat, a = e.addresslng, r = e.address;
        t && wx.openLocation({
            latitude: t,
            longitude: a,
            name: r
        });
    },
    makePhoneCall: function(e, t) {
        wx.makePhoneCall({
            phoneNumber: t,
            success: function() {
                c.default.saveCallRecord(e);
            }
        });
    },
    updateCoverDisplay: function(e, t, a, r, i) {
        i || e.setData({
            coverHieght: r * (a / t),
            isFixCoverHieght: !0
        });
    }
};